

from pico_lin_com import PicoLinCom, _picolin_rsp_message
import time,io,sys


class LinSlaveConformTest():
    def __init__(self, netMan = False, txId = 0x0, rxId = 0x1, txLen = 8, rxLen = 8, rxErrBit = 0):
        self.lin = None    
        self.network_management_enable = netMan
        self.request_id = txId
        self.response_id = rxId
        self.request_len = txLen
        self.response_len = rxLen
        self.response_error_bit = rxErrBit
        self.logPath = "./"
        self.begin_time_stamp = time.time()
        self.log_txt_date = time.strftime(' %Y-%m-%d %H%M%S', time.localtime())
    
    def setDevice(self, device) -> bool:
        ret = True
        if type(device) == PicoLinCom:
            self.lin = device
        else:
            ret = False
        return ret

    def resetTimeStamp(self):
        self.begin_time_stamp = time.time()

    def setLogPath(self, path):
        self.logPath = path
    
    def appendTxtLog(self, content):
        with open(self.logPath + "/lin_test" + self.log_txt_date + ".txt", 'a', encoding='utf-8') as f:
            f.write(content)

    def testNetWorkWakeup(self) -> bool:
        if self.lin is None:
            return False

        msg = self.lin.sendFrame(0x3c, 8, [0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff])
        if type(msg) == _picolin_rsp_message:
            log = "INFO:Wake up network success"
            print(log)
            self.appendTxtLog(log + "\n")
        else:
            log = "INFO:Wake up network failed"
            print(log)
            self.appendTxtLog(log + "\n")  

        return True

    # TG2-TC1
    def testSlaveBaudrateValue(self) -> bool:
        if self.lin is None:
            return False
        
        # reset Master
        self.lin.setMode(0)
        
        print("TEST:BEGIN|[TG2-TC1] LIN从节点波特率测试")
        self.appendTxtLog("TEST:BEGIN|[TG2-TC1] LIN从节点波特率测试\n")

        step_t = 1  

        if self.lin.setTimeStampMode(1) == 0:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置内部时间戳内容为响应数据时间|设置成功|pass".format(step = step_t, time = stamp)
            print(log)
            self.appendTxtLog(log + "\n")
        else:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置内部时间戳内容为响应数据时间|设置失败|fail".format(step = step_t, time = stamp)
            print(log)
            self.appendTxtLog(log + "\n")
            
        step_t += 1

        for i in range(5):
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            stamp = round(time.time() - self.begin_time_stamp, 3)
            if type(msg) == _picolin_rsp_message:
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 0:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
                    interval_us = msg.timestamp
                    baudrate = 80000000 / interval_us
                    if baudrate > 18815 and baudrate < 19584:
                        log = "TEST:{step}|{time}|计算波特率|Baudrate={baud}|pass".format(step = step_t, time = stamp, baud = round(baudrate, 3))
                        print(log)
                        self.appendTxtLog(log + "\n")
                    else:
                        log = "TEST:{step}|{time}|计算波特率|Baudrate={baud}|fail".format(step = step_t, time = stamp, baud = round(baudrate, 3))
                        print(log)
                        self.appendTxtLog(log + "\n") 
                else:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节响应错误|fail".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
            else:
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")   

            step_t += 1              
            
            time.sleep(0.2)

        print("TEST:END|[TG2-TC1] LIN从节点波特率测试")
        self.appendTxtLog("TEST:END|[TG2-TC1] LIN从节点波特率测试\n")
        
        return True

    # TG2-TC2
    def testSlaveBaudrateCompatibility(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)

        print("TEST:BEGIN|[TG2-TC2] LIN从节点波特率兼容性测试")
        self.appendTxtLog("TEST:BEGIN|[TG2-TC2] LIN从节点波特率兼容性测试\n")

        step_t = 1
        
        if self.lin.setBaudrateUpOrDown(1) == 0:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机发送波特率为19100bps(-0.5%)|设置成功|pass".format(step = step_t, time = stamp)
            print(log)
            self.appendTxtLog(log + "\n")
        else:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机发送波特率为19100bps(-0.5%)|设置失败|fail".format(step = step_t, time = stamp)
            print(log)
            self.appendTxtLog(log + "\n")

        step_t += 1

        for i in range(3):
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 0:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
                else:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节响应错误|fail".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
            else:
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")  

            step_t += 1              
            
            time.sleep(0.2)

        if self.lin.setBaudrateUpOrDown(2) == 0:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机发送波特率为19300bps(+0.5%)|设置成功|pass".format(step = step_t, time = stamp)
            print(log)
            self.appendTxtLog(log + "\n")
        else:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机发送波特率为19300bps(+0.5%)|设置失败|fail".format(step = step_t, time = stamp)
            print(log)
            self.appendTxtLog(log + "\n")      

        step_t += 1

        for i in range(3):
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 0:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
                else:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节响应错误|fail".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
            else:
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")  

            step_t += 1              
            
            time.sleep(0.2)

        print("TEST:END|[TG2-TC2] LIN从节点波特率兼容性测试")
        self.appendTxtLog("TEST:END|[TG2-TC2] LIN从节点波特率兼容性测试\n")

        return True
    
    # TG2-TC3
    def testSlaveBreakLengthCompatibility(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)

        print("TEST:BEGIN|[TG2-TC3] LIN从节点Break间隔场长度兼容性测试")
        self.appendTxtLog("TEST:BEGIN|[TG2-TC3] LIN从节点Break间隔场长度兼容性测试\n")

        step_t = 1
        for i in range(2):
            if self.lin.setBreakLength(13) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Break长度为13位|设置成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                stamp = round(time.time() - self.begin_time_stamp, 3)
                if type(msg) == _picolin_rsp_message:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")

                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点未响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                else:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")                
                    step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Break长度为13位|设置失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

            time.sleep(0.2)

        for i in range(2):
            if self.lin.setBreakLength(26) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Break长度为26位|设置成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                stamp = round(time.time() - self.begin_time_stamp, 3)
                if type(msg) == _picolin_rsp_message:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")

                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点未响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                else:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")                
                    step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Break长度为26位|设置失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1   

            time.sleep(0.2)

        for i in range(2):
            if self.lin.setBreakLength(20) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Break长度为20位|设置成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                stamp = round(time.time() - self.begin_time_stamp, 3)
                if type(msg) == _picolin_rsp_message:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")

                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点未响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                else:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")                
                    step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Break长度为20位|设置失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1  

            time.sleep(0.2)

        print("TEST:END|[TG2-TC3] LIN从节点Break间隔场长度兼容性测试")
        self.appendTxtLog("TEST:END|[TG2-TC3] LIN从节点Break间隔场长度兼容性测试\n")

        return True

    # TG2-TC4
    def testSlaveDelimiterLengthCompatibility(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)

        print("TEST:BEGIN|[TG2-TC4] LIN从节点Delimiter界定符长度兼容性测试")
        self.appendTxtLog("TEST:BEGIN|[TG2-TC4] LIN从节点Delimiter界定符长度兼容性测试\n")

        step_t = 1
        for i in range(2):
            if self.lin.setDelimeterLength(1) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Delimiter长度为1位|设置成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                stamp = round(time.time() - self.begin_time_stamp, 3)
                if type(msg) == _picolin_rsp_message:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")

                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点未响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                else:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")                
                    step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Delimiter长度为1位|设置失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

            time.sleep(0.2)

        for i in range(2):
            if self.lin.setDelimeterLength(14) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Delimiter长度为14位|设置成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                stamp = round(time.time() - self.begin_time_stamp, 3)
                if type(msg) == _picolin_rsp_message:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")

                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点未响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                else:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")                
                    step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Delimiter长度为14位|设置失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1    

            time.sleep(0.2)

        for i in range(2):
            if self.lin.setDelimeterLength(10) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Delimiter长度为10位|设置成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                stamp = round(time.time() - self.begin_time_stamp, 3)
                if type(msg) == _picolin_rsp_message:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")

                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点未响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                else:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")                
                    step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头Delimiter长度为10位|设置失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1    

            time.sleep(0.2)

        print("TEST:END|[TG2-TC4] LIN从节点Delimiter界定符长度兼容性测试")
        self.appendTxtLog("TEST:END|[TG2-TC4] LIN从节点Delimiter界定符长度兼容性测试\n")

        return True

    # TG2-TC5
    def testSlaveHeaderLengthCompatibility(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)

        print("TEST:BEGIN|[TG2-TC5] LIN从节点报头长度兼容性测试")
        self.appendTxtLog("TEST:BEGIN|[TG2-TC5] LIN从节点报头长度兼容性测试\n")

        step_t = 1
        for i in range(2):
            if self.lin.setHeaderLength(1) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头长度为13位Break、1位Delimiter、0位InterByte|设置成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                stamp = round(time.time() - self.begin_time_stamp, 3)
                if type(msg) == _picolin_rsp_message:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")

                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点未响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                else:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")                 
                    step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头长度为13位Break、1位Delimiter、0位InterByte|设置失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

            time.sleep(0.2)

        for i in range(2):
            if self.lin.setHeaderLength(2) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头长度为19位Break、2位Delimiter、6位InterByte|设置成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                stamp = round(time.time() - self.begin_time_stamp, 3)
                if type(msg) == _picolin_rsp_message:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")

                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点未响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                else:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")                
                    step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头长度为19位Break、2位Delimiter、6位InterByte|设置失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1    

            time.sleep(0.2)

        for i in range(2):
            if self.lin.setHeaderLength(3) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头长度为15位Break、3位Delimiter、2位InterByte|设置成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                stamp = round(time.time() - self.begin_time_stamp, 3)
                if type(msg) == _picolin_rsp_message:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")

                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点未响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        step_t += 1
                else:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")                
                    step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头长度为15位Break、3位Delimiter、2位InterByte|设置失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1    

            time.sleep(0.2)

        for i in range(2):
            if self.lin.setHeaderLength(4) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头长度为13位Break、1位Delimiter、13位InterByte|设置成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                stamp = round(time.time() - self.begin_time_stamp, 3)
                if type(msg) == _picolin_rsp_message:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")

                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        step_t += 1
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点未响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        step_t += 1
                else:
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")                
                    step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置发送报头长度为13位Break、1位Delimiter、13位InterByte|设置失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1    

            time.sleep(0.2)

        print("TEST:END|[TG2-TC5] LIN从节点报头长度兼容性测试")
        self.appendTxtLog("TEST:END|[TG2-TC5] LIN从节点报头长度兼容性测试\n")

        return True
    
    # TG2-TC6 
    def testSlaveResponseTimeValue(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)

        print("TEST:BEGIN|[TG2-TC6] LIN从节点响应空间时间测试")
        self.appendTxtLog("TEST:BEGIN|[TG2-TC6] LIN从节点响应空间时间测试\n")

        step_t = 1
        
        if self.lin.setTimeStampMode(2) == 0:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置内部时间戳内容为PID结束到CheckSum结束时间|设置成功|pass".format(step = step_t, time = stamp)
            print(log)
            self.appendTxtLog(log + "\n")
        else:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置内部时间戳内容为PID结束到CheckSum结束时间|设置失败|fail".format(step = step_t, time = stamp)
            print(log)
            self.appendTxtLog(log + "\n")
            
        step_t += 1
       
        for i in range(5):
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            stamp = round(time.time() - self.begin_time_stamp, 3)
            if type(msg) == _picolin_rsp_message:
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                interval_ms = msg.timestamp / 1000
                if interval_ms < 6.5:
                    log = "TEST:{step}|{time}|读取响应报文的时间戳|响应空间时间为{interval}ms|pass".format(step = step_t, time = stamp, interval = interval_ms)
                    print(log)
                    self.appendTxtLog(log + "\n")
                else:
                    log = "TEST:{step}|{time}|读取响应报文的时间戳|响应空间时间为{interval}ms|fail".format(step = step_t, time = stamp, interval = interval_ms)
                    print(log)
                    self.appendTxtLog(log + "\n")    
                
                step_t += 1               
            else:
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送失败|fail".format(step = step_t, id = self.response_id, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")    
                step_t += 1             
            
            time.sleep(0.2)

        print("TEST:END|[TG2-TC6] LIN从节点响应空间时间测试")
        self.appendTxtLog("TEST:END|[TG2-TC6] LIN从节点响应空间时间测试\n")

        return True

    # TG2-TC7
    def testSlaveResponseDlc(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)     

        print("TEST:BEGIN|[TG2-TC7] LIN从节点响应数据长度DLC测试")
        self.appendTxtLog("TEST:BEGIN|[TG2-TC7] LIN从节点响应数据长度DLC测试\n")

        step_t = 1
        for i in range(3):
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            stamp = round(time.time() - self.begin_time_stamp, 3)
            if type(msg) == _picolin_rsp_message:
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.dlc == self.response_len:
                    log = "TEST:{step}|{time}|判断响应数据长度DLC是否于要求一致|DLC={dlen}一致|pass".format(step = step_t, time = stamp, dlen = msg.dlc)
                    print(log)
                    self.appendTxtLog(log + "\n")
                    step_t += 1
                else:
                    log = "TEST:{step}|{time}|判断响应数据长度DLC是否于要求一致|DLC={dlen}不一致|fail".format(step = step_t, time = stamp, dlen = msg.dlc)
                    print(log)
                    self.appendTxtLog(log + "\n")    
                    step_t += 1               
            else:
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")    
                step_t += 1             
            
            time.sleep(0.2)

        print("TEST:END|[TG2-TC7] LIN从节点响应数据长度DLC测试")
        self.appendTxtLog("TEST:END|[TG2-TC7] LIN从节点响应数据长度DLC测试\n")

        return True

    # TG2-TC8
    def testSlaveChecksum(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)     

        print("TEST:BEGIN|[TG2-TC8] LIN从节点校验和测试")
        self.appendTxtLog("TEST:BEGIN|[TG2-TC8] LIN从节点校验和测试\n")

        step_t = 1
        for i in range(2):
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 0:
                    log = "TEST:{step}|{time}|判断响应报文校验和是否为增强型校验|CheckSum={ck}为增强型校验|pass".format(step = step_t, time = stamp, ck = msg.checksum)
                    print(log)
                    self.appendTxtLog(log + "\n")
                    step_t += 1
                else:
                    log = "TEST:{step}|{time}|判断响应报文校验和是否为增强型校验|CheckSum={ck}不为增强型校验|fail".format(step = step_t, time = stamp, ck = msg.checksum)
                    print(log)
                    self.appendTxtLog(log + "\n")    
                    step_t += 1               
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的报头, 请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")   
                step_t += 1 

            time.sleep(0.2)     

        for i in range(2):
            msg = self.lin.sendFrame(0x3c, 8, [0x01, 0x2, 0x10, 0x1, 0x0, 0x0, 0x0, 0x0])
            stamp = round(time.time() - self.begin_time_stamp, 3)
            if type(msg) == _picolin_rsp_message:
                log = "TEST:{step}|{time}|主机发送ID为0x3c的诊断报文|发送报文成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1
            else:
                log = "TEST:{step}|{time}|主机发送ID为0x3c的诊断报文|发送报文失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                step_t += 1                

            time.sleep(0.1) 

            msg = self.lin.sendHeader(0x3d, 8)
            stamp = round(time.time() - self.begin_time_stamp, 3)
            if type(msg) == _picolin_rsp_message:
                log = "TEST:{step}|{time}|主机发送ID为0x3d的诊断报头|发送报头成功|pass".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 0:
                    log = "TEST:{step}|{time}|判断响应报文校验和是否为经典型校验|CheckSum={ck}为经典型校验|pass".format(step = step_t, time = stamp, ck = msg.checksum)
                    print(log)
                    self.appendTxtLog(log + "\n")
                    step_t += 1
                else:
                    log = "TEST:{step}|{time}|判断响应报文校验和是否为经典型校验|CheckSum={ck}不为经典型校验|fail".format(step = step_t, time = stamp, ck = msg.checksum)
                    print(log)
                    self.appendTxtLog(log + "\n")    
                    step_t += 1               
            else:
                log = "TEST:{step}|{time}|主机发送ID为0x3d的诊断报头|发送报头失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")   
                step_t += 1       
            
            time.sleep(0.1)       

        print("TEST:END|[TG2-TC8] LIN从节点校验和测试")
        self.appendTxtLog("TEST:END|[TG2-TC8] LIN从节点校验和测试\n")

        return True
    
    # TG2-TC9
    def testSlaveIncompleteHeader(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)        

        print("TEST:BEGIN|[TG2-TC9] LIN从节点不完整帧头响应测试")
        self.appendTxtLog("TEST:BEGIN|[TG2-TC9] LIN从节点不完整帧头响应测试\n")

        step_t = 1
        if self.lin.setIncompleteHeaderFlag(1) == 0:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机只发送Break间隔场|设置成功|pass".format(time = stamp, step = step_t)
            print(log)
            self.appendTxtLog(log + "\n")     
            step_t += 1
        else:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机只发送Break间隔场|设置失败|fail".format(time = stamp, step = step_t)
            print(log)
            self.appendTxtLog(log + "\n")  
            step_t += 1

        
        for i in range(2):
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的不完整报头(Break)，请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 4:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点不响应|pass".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
                else:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|fail".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")    
                step_t += 1               
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的不完整报头(Break)，请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")  
                log = "TEST:{step}|{time}|判断从节点是否响应|前置条件失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")    
                step_t += 1 

            time.sleep(0.2) 

        if self.lin.setIncompleteHeaderFlag(2) == 0:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机只发送Break+Sync间隔场和同步场|设置成功|pass".format(time = stamp, step = step_t)
            print(log)
            self.appendTxtLog(log + "\n")     
            step_t += 1
        else:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机只发送Break+Sync间隔场和同步场|设置失败|fail".format(time = stamp, step = step_t)
            print(log)
            self.appendTxtLog(log + "\n")  
            step_t += 1

        for i in range(2):
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的不完整报头(Break+Sync)，请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 4:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点不响应|pass".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
                else:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|fail".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")    
                step_t += 1               
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的不完整报头(Break+Sync)，请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")  
                log = "TEST:{step}|{time}|判断从节点是否响应|前置条件失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")    
                step_t += 1 

            time.sleep(0.2) 

        if self.lin.setIncompleteHeaderFlag(3) == 0:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机发送报头的PID异常|设置成功|pass".format(time = stamp, step = step_t)
            print(log)
            self.appendTxtLog(log + "\n")     
            step_t += 1
        else:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:1{step}|{time}|设置主机发送报头的PID异常|设置失败|fail".format(time = stamp, step = step_t)
            print(log)
            self.appendTxtLog(log + "\n")  
            step_t += 1

        for i in range(2):
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送PID（{id}）异常的不完整报头，请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 4:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点不响应|pass".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
                else:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|fail".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")    
                step_t += 1               
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送PID（{id}）异常的不完整报头，请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")  
                log = "TEST:{step}|{time}|判断从节点是否响应|前置条件失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")    
                step_t += 1 

            time.sleep(0.2) 

        print("TEST:END|[TG2-TC9] LIN从节点不完整帧头响应测试")
        self.appendTxtLog("TEST:END|[TG2-TC9] LIN从节点不完整帧头响应测试\n")

        return True
    
    # TG2-TC10
    def testSlaveHeaderPIDError(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)        

        print("TEST:BEGIN|[TG2-TC10] LIN从节点PID校验错误响应测试")
        self.appendTxtLog("TEST:BEGIN|[TG2-TC10] LIN从节点PID校验错误响应测试\n")

        step_t = 1

        for i in range(2):
            # 设置不完整报头模式为PID非正常PID
            if self.lin.setIncompleteHeaderFlag(3) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置主机发送的报头PID校验错误|设置成功|pass".format(time = stamp, step = step_t)
                print(log)
                self.appendTxtLog(log + "\n")     
                step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置主机发送的报头PID校验错误|设置失败|fail".format(time = stamp, step = step_t)
                print(log)
                self.appendTxtLog(log + "\n")  
                step_t += 1

            # 发送报头
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送PID（{id}）校验错误的报头，请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 4:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点不响应|pass".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
                else:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|fail".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")    
                step_t += 1               
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送PID（{id}）校验错误的报头，请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")  
                step_t += 1 

            time.sleep(0.2) 

            # 设置报头为完整报头
            if self.lin.setIncompleteHeaderFlag(0) == 0:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置主机发送的报头PID校验正确|设置成功|pass".format(time = stamp, step = step_t)
                print(log)
                self.appendTxtLog(log + "\n")     
                step_t += 1
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|设置主机发送的报头PID校验正确|设置失败|fail".format(time = stamp, step = step_t)
                print(log)
                self.appendTxtLog(log + "\n")  
                step_t += 1

            # 发送报头 response error = 1
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送PID（{id}）校验正确的报头，请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 0:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
                    byte_i = int(self.response_error_bit / 8)
                    bit_i = self.response_error_bit % 8
                    mask = 0x1 << bit_i
                    if (msg.bytes[byte_i] & mask) != 0x0:
                        log = "TEST:{step}|{time}|判断响应reponse error位是否置1|reponse error=1|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")       
                    else:
                        log = "TEST:{step}|{time}|判断响应reponse error位是否置1|reponse error=0|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")                                          
                else:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点不响应|fail".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")   

                step_t += 1               
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送PID（{id}）校验正确的报头，请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")    
                step_t += 1 

            time.sleep(0.2) 

            # 发送报头 response error = 0
            msg = self.lin.sendHeader(self.response_id, self.response_len)
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送PID（{id}）校验正确的报头，请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                print(log)
                self.appendTxtLog(log + "\n")
                if msg.event == 0:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")
                    byte_i = int(self.response_error_bit / 8)
                    bit_i = self.response_error_bit % 8
                    mask = 0x1 << bit_i
                    if (msg.bytes[byte_i] & mask) == 0x0:
                        log = "TEST:{step}|{time}|判断响应reponse error位是否置0|reponse error=0|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")       
                    else:
                        log = "TEST:{step}|{time}|判断响应reponse error位是否置0|reponse error=1|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")                                          
                else:
                    log = "TEST:{step}|{time}|判断从节点是否响应|从节点不响应|fail".format(step = step_t, time = stamp)
                    print(log)
                    self.appendTxtLog(log + "\n")    
                step_t += 1               
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送PID（{id}）校验正确的报头，请求响应|发送报头失败|fail".format(step = step_t, time = stamp)
                print(log)
                self.appendTxtLog(log + "\n")   
                step_t += 1 

            time.sleep(0.2) 

        print("TEST:END|[TG2-TC10] LIN从节点PID校验错误响应测试")
        self.appendTxtLog("TEST:END|[TG2-TC10] LIN从节点PID校验错误响应测试\n")

        return True        
    
    # TG3-TC1
    def testSlaveChecksumError(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)        

        print("TEST:BEGIN|[TG3-TC1] LIN从节点数据校验错误响应测试")
        self.appendTxtLog("TEST:BEGIN|[TG3-TC1] LIN从节点数据校验错误响应测试\n")

        step_t = 1

        if self.lin.setErrorBitFlag(2) == 0:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机发送报文数据校验错误|设置成功|pass".format(time = stamp, step = step_t)
            print(log)
            self.appendTxtLog(log + "\n")     
            step_t += 1
        else:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机发送报文数据校验错误|设置失败|fail".format(time = stamp, step = step_t)
            print(log)
            self.appendTxtLog(log + "\n")  
            step_t += 1

        for i in range(2):
            msg = self.lin.sendFrame(self.request_id, self.request_len, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0])
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的报文|发送报文成功|pass".format(step = step_t, time = stamp, id = self.request_id)
                print(log)
                self.appendTxtLog(log + "\n")

                time.sleep(0.2) 

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                if type(msg) == _picolin_rsp_message:
                    stamp = round(time.time() - self.begin_time_stamp, 3)
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")       
                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        byte_i = int(self.response_error_bit / 8)
                        bit_i = self.response_error_bit % 8
                        mask = 0x1 << bit_i
                        if (msg.bytes[byte_i] & mask) != 0x0:
                            log = "TEST:{step}|{time}|判断响应reponse error位是否置1|reponse error=1|pass".format(step = step_t, time = stamp)
                            print(log)
                            self.appendTxtLog(log + "\n")       
                        else:
                            log = "TEST:{step}|{time}|判断响应reponse error位是否置1|reponse error=0|fail".format(step = step_t, time = stamp)
                            print(log)
                            self.appendTxtLog(log + "\n")                     
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点不响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")  
                else:
                    stamp = round(time.time() - self.begin_time_stamp, 3)
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")  

                step_t += 1

                time.sleep(0.2) 

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                if type(msg) == _picolin_rsp_message:
                    stamp = round(time.time() - self.begin_time_stamp, 3)
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")       
                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        byte_i = int(self.response_error_bit / 8)
                        bit_i = self.response_error_bit % 8
                        mask = 0x1 << bit_i
                        if (msg.bytes[byte_i] & mask) == 0x0:
                            log = "TEST:{step}|{time}|判断响应reponse error位是否置0|reponse error=0|pass".format(step = step_t, time = stamp)
                            print(log)
                            self.appendTxtLog(log + "\n")       
                        else:
                            log = "TEST:{step}|{time}|判断响应reponse error位是否置0|reponse error=1|fail".format(step = step_t, time = stamp)
                            print(log)
                            self.appendTxtLog(log + "\n")                     
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点不响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")  
                else:
                    stamp = round(time.time() - self.begin_time_stamp, 3)
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")  

                step_t += 1   
                time.sleep(0.2)         
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的报文|发送报文失败|fail".format(step = step_t, time = stamp, id = self.request_id)
                print(log)
                self.appendTxtLog(log + "\n")   
                step_t += 1 
                time.sleep(0.2) 
   

        print("TEST:END|[TG3-TC1] LIN从节点数据校验错误响应测试")
        self.appendTxtLog("TEST:END|[TG3-TC1] LIN从节点数据校验错误响应测试\n")

        return True
    
    # TG3-TC2
    def testSlaveDataError(self) -> bool:
        if self.lin is None:
            return False       
        
        # reset Master
        self.lin.setMode(0)        

        print("TEST:BEGIN|[TG3-TC2] LIN从节点数据位错误响应测试")
        self.appendTxtLog("TEST:BEGIN|[TG3-TC2] LIN从节点数据位错误响应测试\n")

        step_t = 1

        if self.lin.setErrorBitFlag(3) == 0:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机发送报文数据位错误|设置成功|pass".format(time = stamp, step = step_t)
            print(log)
            self.appendTxtLog(log + "\n")     
            step_t += 1
        else:
            stamp = round(time.time() - self.begin_time_stamp, 3)
            log = "TEST:{step}|{time}|设置主机发送报文数据位错误|设置失败|fail".format(time = stamp, step = step_t)
            print(log)
            self.appendTxtLog(log + "\n")  
            step_t += 1

        for i in range(2):
            msg = self.lin.sendFrame(self.request_id, self.request_len, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0])
            if type(msg) == _picolin_rsp_message:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的报文|发送报文成功|pass".format(step = step_t, time = stamp, id = self.request_id)
                print(log)
                self.appendTxtLog(log + "\n")

                time.sleep(0.2) 

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                if type(msg) == _picolin_rsp_message:
                    stamp = round(time.time() - self.begin_time_stamp, 3)
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")       
                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        byte_i = int(self.response_error_bit / 8)
                        bit_i = self.response_error_bit % 8
                        mask = 0x1 << bit_i
                        if (msg.bytes[byte_i] & mask) != 0x0:
                            log = "TEST:{step}|{time}|判断响应reponse error位是否置1|reponse error=1|pass".format(step = step_t, time = stamp)
                            print(log)
                            self.appendTxtLog(log + "\n")       
                        else:
                            log = "TEST:{step}|{time}|判断响应reponse error位是否置1|reponse error=0|fail".format(step = step_t, time = stamp)
                            print(log)
                            self.appendTxtLog(log + "\n")                     
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点不响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")  
                else:
                    stamp = round(time.time() - self.begin_time_stamp, 3)
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")  

                step_t += 1

                time.sleep(0.2) 

                msg = self.lin.sendHeader(self.response_id, self.response_len)
                if type(msg) == _picolin_rsp_message:
                    stamp = round(time.time() - self.begin_time_stamp, 3)
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送报头成功|pass".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")       
                    if msg.event == 0:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点响应|pass".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")
                        byte_i = int(self.response_error_bit / 8)
                        bit_i = self.response_error_bit % 8
                        mask = 0x1 << bit_i
                        if (msg.bytes[byte_i] & mask) == 0x0:
                            log = "TEST:{step}|{time}|判断响应reponse error位是否置0|reponse error=0|pass".format(step = step_t, time = stamp)
                            print(log)
                            self.appendTxtLog(log + "\n")       
                        else:
                            log = "TEST:{step}|{time}|判断响应reponse error位是否置0|reponse error=1|fail".format(step = step_t, time = stamp)
                            print(log)
                            self.appendTxtLog(log + "\n")                     
                    else:
                        log = "TEST:{step}|{time}|判断从节点是否响应|从节点不响应|fail".format(step = step_t, time = stamp)
                        print(log)
                        self.appendTxtLog(log + "\n")  
                else:
                    stamp = round(time.time() - self.begin_time_stamp, 3)
                    log = "TEST:{step}|{time}|主机发送ID为{id}的报头，请求响应|发送报头失败|fail".format(step = step_t, time = stamp, id = self.response_id)
                    print(log)
                    self.appendTxtLog(log + "\n")  

                step_t += 1   
                time.sleep(0.2)         
            else:
                stamp = round(time.time() - self.begin_time_stamp, 3)
                log = "TEST:{step}|{time}|主机发送ID为{id}的报文|发送报文失败|fail".format(step = step_t, time = stamp, id = self.request_id)
                print(log)
                self.appendTxtLog(log + "\n")   
                step_t += 1 
                time.sleep(0.2) 
   

        print("TEST:END|[TG3-TC2] LIN从节点数据位错误响应测试")
        self.appendTxtLog("TEST:END|[TG3-TC2] LIN从节点数据位错误响应测试\n")

        return True